Trò chơi Angry Birds trong UNITY Engine
31.677 lượt xem;
- MaterialColorTweenProperty.cs
- specificTypes /
- properties /
- GoKit /
- Plugins /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4
5 public class MaterialColorTweenProperty : AbstractColorTweenProperty
6 {
7 private string _materialColorName;
8
9
10 public MaterialColorTweenProperty( Color endValue, string colorName = "_Color", bool isRelative = false ) : base( endValue, isRelative )
11 {
12 _materialColorName = colorName;
13 }
14
15
16 #region Object overrides
17
18 public override int GetHashCode()
19 {
20 return base.GetHashCode();
21 }
22
23
24 public override bool Equals( object obj )
25 {
26 // start with a base check and then compare our material names
27 if( base.Equals( obj ) )
28 return this._materialColorName == ((MaterialColorTweenProperty)obj)._materialColorName;
29
30 return false;
31 }
32
33 #endregion
34
35
36 public override void prepareForUse()
37 {
38 _endValue = _originalEndValue;
39
40 // if this is a from tween we need to swap the start and end values
41 if( _ownerTween.isFrom )
42 {
43 _startValue = _endValue;
44 _endValue = _target.GetColor( _materialColorName );
45 }
46 else
47 {
48 _startValue = _target.GetColor( _materialColorName );
49 }
50
51 base.prepareForUse();
52 }
53
54
55 public override void tick( float totalElapsedTime )
56 {
57 var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
58 var color = GoTweenUtils.unclampedColorLerp( _startValue, _diffValue, easedTime );
59
60 _target.SetColor( _materialColorName, color );
61 }
62
63 }
2 using System.Collections;
3
4
5 public class MaterialColorTweenProperty : AbstractColorTweenProperty
6 {
7 private string _materialColorName;
8
9
10 public MaterialColorTweenProperty( Color endValue, string colorName = "_Color", bool isRelative = false ) : base( endValue, isRelative )
11 {
12 _materialColorName = colorName;
13 }
14
15
16 #region Object overrides
17
18 public override int GetHashCode()
19 {
20 return base.GetHashCode();
21 }
22
23
24 public override bool Equals( object obj )
25 {
26 // start with a base check and then compare our material names
27 if( base.Equals( obj ) )
28 return this._materialColorName == ((MaterialColorTweenProperty)obj)._materialColorName;
29
30 return false;
31 }
32
33 #endregion
34
35
36 public override void prepareForUse()
37 {
38 _endValue = _originalEndValue;
39
40 // if this is a from tween we need to swap the start and end values
41 if( _ownerTween.isFrom )
42 {
43 _startValue = _endValue;
44 _endValue = _target.GetColor( _materialColorName );
45 }
46 else
47 {
48 _startValue = _target.GetColor( _materialColorName );
49 }
50
51 base.prepareForUse();
52 }
53
54
55 public override void tick( float totalElapsedTime )
56 {
57 var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
58 var color = GoTweenUtils.unclampedColorLerp( _startValue, _diffValue, easedTime );
59
60 _target.SetColor( _materialColorName, color );
61 }
62
63 }